package com.huawei.appmarket.framework.app;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Process;
import com.huawei.appmarket.R;
import com.huawei.appmarket.framework.entry.EntranceService;
import com.huawei.appmarket.service.externalapi.control.HiAppBuoyProtocolChecker;
import com.huawei.appmarket.service.installresult.control.InstallerReceiver;
import com.huawei.appmarket.service.thirdzone.ThirdAppZoneActivity;
import com.huawei.appmarket.support.storage.DbProvider;
import com.huawei.fastengine.fastview.download.utils.PackageUtils;
import com.huawei.kidsCenter.KidsCenterActivity;
import java.util.List;
import o.ayy;
import o.HwDisplayRegionUtils;
import o.bkt;
import o.bod;
import o.bus;
import o.ccz;
import o.cdb;
import o.cdj;
import o.cdn;
import o.cdp;
import o.cef;
import o.cju;
import o.clv.c;
import o.clw;
import o.cvt;
import o.dgh;
import o.dgi;
import o.dgj;
import o.dgk;
import o.dgl;
import o.dgm;
import o.dgn;
import o.dgs;
import o.dhq;
import o.dip;
import o.dis;
import o.div;
import o.dkk;
import o.dlq;
import o.dmy;
import o.Logger;
import o.doe;
import o.dok;
import o.ContentManager;
import o.dou;
import o.dov;
import o.dow;
import o.dox;
import o.doy;
import o.doz;
import o.dpd;
import o.dpf;
import o.dpg;
import o.dpm;
import o.dpq;
import o.dps;
import o.dqo;
import o.dqr;
import o.dqu;
import o.dqx;
import o.dqy;
import o.dqz;
import o.drb;
import o.drc;
import o.dsl;
import o.dsm;
import o.dss;
import o.dtx;
import o.dtz;
import o.dud;
import o.dug;
import o.duj;
import o.dum;
import o.duq;
import o.dut;
import o.duu;
import o.duv.d;
import o.duy;
import o.dvg;
import o.dxr;
import o.dxs;
import o.dxw;
import o.dyj;
import o.dym;
import o.dyq;
import o.dzd;
import o.dzy;
import o.ebq;
import o.ecx;
import o.edx;
import o.edy;
import o.eec;
import o.eef;
import o.eex;
import o.eff;
import o.efk;
import o.efz;
import o.ego;
import o.egv;
import o.eht;
import o.ekk;
import o.ena;
import o.eng;
import o.eoe;
import o.eoq;
import o.eov;
import o.epp;
import o.eqk;
import o.eqp;
import o.eqt;
import o.erb;
import o.ety;
import o.ActivityUtil;
import o.ewn;
import o.ewq;
import o.exw;
import o.fbd;
import o.fbi;
import o.fho;
import o.lw;

public class StoreApplication extends Application {
    private static final String TAG = "StoreApplication";
    private static StoreApplication instance = null;
    private final BroadcastReceiver localeChangedReceiver = new BroadcastReceiver(this) {
        final /* synthetic */ StoreApplication ˋ;

        {
            this.ˋ = r1;
        }

        public void onReceive(Context context, Intent intent) {
            this.ˋ.notifyLocalchange();
        }
    };
    private ewn wisedistApp;

    public StoreApplication() {
        cdj.ˏ("907112");
        ContentManager.build(this);
        setInstance(this);
        registerExternalActivity();
        dhq.ॱ(true);
        cdb.ॱ(edx.class, new edy());
        cdb.ॱ(eov.class, new dox());
        dzd.ॱ((Context) this).ˎ();
    }

    public static StoreApplication getInstance() {
        return instance;
    }

    private static void setInstance(StoreApplication storeApplication) {
        instance = storeApplication;
    }

    public static boolean isLegalProcess(Context context) {
        String str;
        int myPid = Process.myPid();
        List<RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) context.getSystemService("activity")).getRunningAppProcesses();
        if (runningAppProcesses != null) {
            for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
                if (runningAppProcessInfo.pid == myPid) {
                    str = runningAppProcessInfo.processName;
                    break;
                }
            }
        }
        str = null;
        if (str == null) {
            Logger.ˋ(TAG, "canot get processname, current processid:" + myPid);
            return true;
        } else if (str.equalsIgnoreCase(PackageUtils.HWGAMEBOX_PACKAGE_NAME) || str.equalsIgnoreCase("com.huawei.appmarket")) {
            return true;
        } else {
            Logger.ˋ(TAG, "Unknow ProcName:" + str);
            return false;
        }
    }

    protected void attachBaseContext(Context context) {
        super.attachBaseContext(context);
        if (isLegalProcess(this)) {
            cvt.setApsid_(System.currentTimeMillis());
            lw.ˊ((Context) this);
            Logger.ॱ(dqy.ˎ());
            Logger.ˏ(epp.ˊ(this));
            clw.ˋ(this, c.ॱ().ˏ(4).ˋ(false).ˎ(false).ˎ(new dmy()).ˋ());
            drc.ˏ(this);
            Logger.ˎ(TAG, "HiSpace startup, the version is: " + cdn.ˎ(this) + ", sdkversion:" + doe.ˎ());
            ewq.ˏ(this);
            dok.ॱ(this);
            eqt.ˋ(dgs.class);
            ebq.ॱ().ˊ();
            ccz.ˎ(0);
            ccz.ˋ("HiSpace_");
            eqk.ˏ(new drb(this));
            this.wisedistApp = new ewn(this);
            dug.ˊ(true);
            dis.ˋ().ॱ(eef.class);
            dss.ॱ().ˊ(true);
            dut.ˊ();
            fbd.ˋ();
            eht.ॱ();
        }
    }

    public void onCreate() {
        super.onCreate();
        if (isLegalProcess(this)) {
            dqy.ˏ();
            dvg.ˊ().ˋ(getApplicationContext());
            dlq.ˎ(getApplicationContext());
            this.wisedistApp.ˋ();
            ety.ˋ("IServiceStub", dou.class);
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.intent.action.LOCALE_CHANGED");
            ActivityUtil.registerReceiver(this, intentFilter, this.localeChangedReceiver);
            dsl.ˋ(DbProvider.class);
            dsl.ॱ();
            InstallerReceiver.setIsReportUninstall(true);
            initAnalytics();
            initCustomColumnConfig();
            dqz.ˊ();
            dqu.ˎ();
            duq.ˊ();
            duy.ˊ();
            eec.ˊ().ˋ();
            duu.ˎ();
            erb.ˊ(null);
            initProtocolObserver();
            new d().ˏ(900086000020126878L).ˏ().ˊ();
            new fbi.c().ˏ().ˏ();
            dgj.ˎ(getApplicationContext());
            dgl.ˊ(getApplicationContext());
            dyj.ॱ();
            dym.ˊ(dyq.class);
            dip.ˊ(HiAppBuoyProtocolChecker.class);
            dpm.ॱ();
            initMultyDeviceAppSyn();
            eoq.ˏ("manual", new dow());
            eoq.ˏ("auto_login", new dov());
            eoq.ˏ("st_error_retry", new doy());
            eoq.ˏ("auto_login_from_desktop", new doz());
            initReserveFilter();
            dss.ॱ().ˋ("HiAppRedDot", new dud());
            dss.ॱ().ॱ(true);
            dgk.ॱ();
            Logger.ˎ(TAG, "create application.");
            ((bus) fho.ˏ().ˋ("Forum").ॱ(bus.class)).ˋ(bus.c.ˎ);
            dum.ॱ().ˋ();
            ena.ˏ();
            cef.ˎ();
            dgi.ˏ().ˎ(this);
            cdp.ˎ();
            ayy.ˋ().ॱ();
            dgn.ˏ();
            initTaskInfo();
            egv.ˏ(efz.class);
            egv.ॱᐝ().ˋ(this, null);
            ((bod) bkt.ˋ("DynamicCore", bod.class)).ˊ(this, new dxs());
            duj.ˏ().ˊ(dxr.class);
            duj.ˏ().ˊ(dxw.class);
            EntranceService.checkEntranceServiceValid(getApplicationContext());
            keepSelfAlive();
            ego.ॱ().ˎ(R.string.gameservice_lite_scope_id);
        }
    }

    private void initProtocolObserver() {
        div.ˎ(getProtocolObserver());
    }

    private div.d getProtocolObserver() {
        return new div.d(this) {
            final /* synthetic */ StoreApplication ॱ;

            {
                this.ॱ = r1;
            }

            public void ॱ(boolean z) {
                if (z) {
                    new Handler().postDelayed(new 4(this), 10000);
                    this.ॱ.initAnalytics();
                    dhq.ॱ().ˋ();
                    exw.ˎ(this.ॱ, "third");
                    return;
                }
                dhq.ॱ().ˊ();
            }
        };
    }

    private void notifyLocalchange() {
        dzy.ॱ(null);
        dok.ʽ();
    }

    public void onTerminate() {
        if (isLegalProcess(this)) {
            this.wisedistApp.ॱ();
            dkk.ˏ();
            dsm.ˎ();
            dgh.ˊ();
            dtz.ॱ().ˏ();
            if (this.localeChangedReceiver != null) {
                ActivityUtil.unregisterReceiver((Context) this, this.localeChangedReceiver);
            }
            dgi.ˏ().ˎ();
            cdp.ˏ();
            HwDisplayRegionUtils.ˎ();
            dgn.ॱ();
            super.onTerminate();
        }
    }

    private void initCustomColumnConfig() {
        cju.ॱ("customColumn.personcenter", "marketpersonal.fragment");
        cju.ॱ("custom.personcenter.oversea", "marketpersonaloversea.fragment");
        cju.ॱ("mw4c", "webview_fragment");
        cju.ॱ("customColumn.managercenter", "manager.fragment");
    }

    private void initReserveFilter() {
        eff.ˊ().ॱ(eex.class);
    }

    private void initMultyDeviceAppSyn() {
        dps.ˎ(dtx.class);
    }

    private void initAnalytics() {
        dqr.ॱ(new dqo());
        dqr.ˏ(new dqx(ContentManager.getInstant().getContext()));
    }

    private void registerExternalActivity() {
        dpg.ॱ("appdetail.activity");
        dpg.ॱ("hifolder.appdetail.activity");
        dpg.ॱ("updatemgr.activity");
        dpg.ˊ("webview.activity", new eng());
        dpg.ॱ("installmgr.activity");
        dpg.ॱ("market.activity");
        dpg.ॱ("kidscenter.activity");
        dpg.ॱ("educenter.activity");
        dpg.ॱ("appdetailreply.activity");
        dpg.ॱ("wish.detail.activity");
        dpg.ॱ("install.depend.activity");
        dpg.ˊ("cardlist_activity", new ekk());
        dpf.ˏ("com.huawei.appmarket.service.wlanapp.WlanAppZoneActivity", new eoe());
        dpf.ˋ(ThirdAppZoneActivity.class.getCanonicalName());
        dpf.ˏ("com.huawei.appmarket.service.paymentapp.PaymentAppZoneActivity", new ecx());
        dpf.ˋ(KidsCenterActivity.class.getCanonicalName());
        dpd.ˋ("Search", "Search");
        dpg.ˊ("search.activity", new efk());
        dpd.ˋ("Section", "section_detail_activity");
        dpd.ˋ("Posts", "post.detail.activity");
        dpd.ˋ("Option", "option.publish");
    }

    private void initTaskInfo() {
        dgm.ˏ(0, R.string.app_name, R.drawable.appmarket_icon, "market.activity");
        dgm.ˏ(17, R.string.kidschannel_app_name, R.drawable.appmarket_icon, "kidcentermain.activity");
        dgm.ˏ(18, R.string.educhannel_app_name, R.drawable.appmarket_icon, "educentermain.activity");
    }

    private void keepSelfAlive() {
        if (!eqp.ॱॱ()) {
            new dpq().start();
        }
    }
}
